package org.hot100_6.leetcode206;

import org.leetcode.easy.ListNode;
import org.utils.ListNode.ListNodeUtils;

public class Solution2 {
    public static void main(String[] args) {
        int [] arr = {1,2,3,4,5};
//        ListNode listNode = ListNodeUtils.createListNode(arr);
//        ListNodeUtils.Print(listNode);
//        System.out.println("----------------");
//        ListNode reverseList = reverseList(listNode);
//        ListNodeUtils.Print(reverseList);
    }

    public static ListNode reverseList(ListNode head){

        if (head==null || head.next == null){
            return head;
        }

        ListNode next = null;
        ListNode pre = null;

        while (head!=null){
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }

        return pre;
    }


}
